<template>
  <!-- <div id="nav">
    <router-link to="/">Home</router-link> |
    <router-link to="/about">About</router-link>
  </div> -->
  <router-view/>
  <!-- <transition name="van-fade">
		<keep-alive include="case,manage,fans">
			<router-view/>
		</keep-alive>
	</transition> -->
</template>

<script>
export default{
  mounted() {
    const _this = this;
    // _this.getWeixinConfig();
  },
  methods: {
    getWeixinConfig() {
      const _this = this;
      let params = {}
      _this.$request.getWeixinConfig(params).then(res=>{
        _this.$store.commit('setAppid', res.data.value.appid)
        _this.$store.commit('setSecret', res.data.value.secret)
        _this.$store.commit('setMininum', res.data.value.minimum) // 最小提现金额
        localStorage.setItem("MININUM", res.data.value.minimum)
        //_this.getCode(res.data.value.appid)
        if (process.env.NODE_ENV == 'production') {
          _this.getCode(res.data.value.appid)
        }
      })
    },
    getCode (appid) { // 非静默授权，第一次有弹框
      const _this = this;
      const code = this.getUrlParam('code') // 截取路径中的code，如果没有就去微信授权，如果已经获取到了就直接传code给后台获取openId
      const local = window.location.href
      if (code == null || code === '') {
        window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='+ appid +'&redirect_uri=' + encodeURIComponent(local) + '&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect'
      } else {
        _this.$store.commit('setCode', code)
        _this.getOpenId(code) //把code传给后台获取用户信息
      }
    },
    getUrlParam(name) {
      var reg=new RegExp('(^|&)'+name+'=([^&]*)(&|$)')
      var r=window.location.search.substr(1).match(reg)
      if(r!=null) return unescape(r[2])
      return null
    },
    // getUserInfo(access_token, open_id) {
    //   // let getUserUrl = `https://api.weixin.qq.com/sns/userinfo?access_token=${access_token}&openid=${open_id}⟨=zh_CN`;
      
    //   const _this = this;
    //   let params = {
    //       access_token: access_token,
    //       open_id: open_id
    //   }
    //   _this.$request.getUserInfo(params).then(res=>{
    //     alert("userInfo:"+JSON.stringify(res))
    //   })
    // },
    getFansItem(item) {
      const _this = this;
      let params = {
          openid: item.openid,
          nickname: item.nickname,
          name: item.nickname,
          avatar: item.avatar,
          province: item.province,
          city: item.city,
      }
      _this.$request.getFansItem(params).then(res=>{
        //默认
      })
    },
    getOpenId(code) {
      const _this = this;
      let params = {
          appid: _this.$store.state.appid,
          secret: _this.$store.state.secret,
          code: code
      }
      _this.$request.getOpenid(params).then(res=>{
          const userInfo = res.data[0];
          const openid = userInfo["openid"];
          const nickname = userInfo["nickname"];
          const headimgurl = userInfo["headimgurl"];
          const province = userInfo["province"]
          const city = userInfo["city"]
          _this.$store.commit('setOpenid', openid)
          localStorage.setItem('OPENID', openid)
          const item = {
            openid,
            nickname,
            avatar:headimgurl,
            province,
            city,
            name:nickname
          }
          _this.$store.commit('setUserInfo',item)
          let a = []
          a.push(item)
          _this.getFansItem(item)
      })
    }
  }
}
</script>


<style lang="scss">
@import '@/assets/css/variable';
html{
  font-size: 10px !important;
  min-height: 100%;
}
@media only screen and (max-width: 374px) {
    /* iphone5 或者更小的尺寸，以 iphone5 的宽度（320px）比例设置 font-size */
    html {
        font-size: 10px !important;
    }
}
@media only screen and (min-width: 375px) and (max-width: 413px) {
    /* iphone6/7/8 和 iphone x */
    html {
        font-size: 11px !important;
    }
}
@media only screen and (min-width: 414px) {
    /* iphone6p 或者更大的尺寸，以 iphone6p 的宽度（414px）比例设置 font-size */
    html {
        font-size: 12px !important;
    }
}
html{
	display: flex;
	flex-direction: column;
}
body{
	flex:1;
	display: flex;
	flex-direction: column;
}
.wrapper{
	flex:1;
	display: flex;
	flex-direction: column;
}
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100%;
  box-sizing: border-box;
}
// 改变vant组件样式
.van-tabs__wrap{
	border-bottom: 1px solid #f4f4f4;
}

//其他样式
p{
  margin-bottom: 0 !important;
}
.load-more{
  text-align: center;
  background-color: white;
  margin: 0 1rem;
}
.no-data{
  text-align: center;
  color:$color3;
}
.d-none{
  display: none;
}
.padding-all{
  padding: 0.8rem;
}
.padding-all-m{
  padding: 1.4rem;
}
.padding-all-l{
  padding: 1.7rem;
}
.padding-lr{
  padding-left: 0.8rem;
  padding-right: 0.8rem;
}
.padding-lr-l{
  padding-left: 1.6rem;
  padding-right: 1.6rem;
}
.border-r-l{
  border-radius: 0.8rem;
}
.border-r-m{
  border-radius: 0.6rem;
}
.color-blue{color: blue;}
.color-red{color: red;}
.color-green{color: green;}
.color-ll{color: #111;}
.color-l{color: #333;}
.color-m{color: #666;}
.color-s{color: #999;}
.margT-s{margin-top:0.3rem;}
.margT-m{margin-top:0.4rem;}
.margT-l{margin-top:1rem;}
.margL-m{margin-left:0.6rem;}
.margL-l{margin-left:1rem;}
.margB-l{margin-bottom:1rem;}
.titleMoreBox {
	padding: 2rem 1.8rem 0 1.8rem;
	display: flex;
	align-items: center;
	justify-content: space-between;

	.title {
		font-size: 1.6rem;
		font-weight: bold;
	}

	.more {
		display: flex;
		align-items: center;
		color: #999999;
	}
}
.t-center{
  text-align: center;
}
.t-bold{
  font-weight: bold;
}
.tabbar-height{
  height: 50px;
  width: 100%;
  background-color: $main-bgc;
}
.tabbar-height-white{
  height: 50px;
  width: 100%;
  background-color: $main-bgc-white;
}
.line-height-m{
  line-height: 1.3em;
}
.line-height-l{
  line-height: 1.5em;
}
.splitLine{
	width: 100%;
	height: 1em;
	background-color: $main-bgc;
}
.main-bg-gray{
  background-color: $main-bgc;
}
.main-bg-white{
  background-color: $main-bgc-white;
}
.main-bg{
  background-color: $main-bgc;
}
.title-l{
  font-size: 1.8rem;
  font-weight: bold;
  color: #111;
}
.title-m{
  font-size: 1.6rem;
  font-weight: bold;
  color: #222;
}
.title-s{
  font-size: 1.4rem;
  font-weight: bold;
  color: #333;
}
.fs-10{ font-size: 1rem; }
.fs-12{ font-size: 1.2rem; }
.fs-13{ font-size: 1.3rem; }
.fs-14{ font-size: 1.4rem; }
.fs-15{ font-size: 1.5rem; }
.fs-16{ font-size: 1.6rem; }
.fs-18{ font-size: 1.8rem; }
</style>
